<template>
	<view>
		
			<top-bar fixed="relative"></top-bar>
		
		<view class="address">
			<text class="cuIcon-location icon"></text>
			<view>
				<view>{{ detail.address }}</view>
				<view class="tel">{{ detail.addressUser }} {{ detail.tel }}</view>
			</view>
		</view>
		
		<view class="goods">
			<!--<view class="title">十足店</view>-->
			<view class="content">
				<view class="image">
					<image v-if="detail.coverPhoto" :src="detail.coverPhoto"></image>
					<image v-else src="/static/noPic.png"></image>
				</view>
				<view class="main">
					<view class="head">
						<text class="name">{{detail.prodName}}</text>
						<text class="price">￥{{detail.price}}</text>
					</view>
					<view class="info">
						<text class=""></text>
						<text class="num">x{{ detail.cartNum }}</text>
					</view>
				</view>
			</view>
			<view class="operate">
				<template v-if="detail.state == 1001">
					<text class="btn" @click="cancelOrder()">取消</text>
					<text class="btn" @click="toServicesPay()">立即下单</text>
				</template>
				<template class="btn" v-if="detail.state == 2102">
					<text class="btn" @click="to_return()">退款</text>
					<text class="btn" @click="_expeditingDelivery()">催一下</text>
				</template>
				<template class="btn" v-if="detail.state == 3103 && detail.cartType =='3306'">
					<text class="btn" @click="_expeditingDelivery()">催一下</text>
				</template>
				<template class="btn" v-if="detail.state == 3104">
					<text class="btn" @click="_toPay()">支付</text>
				</template>
				<template class="btn" v-if="detail.state == 4004">
					<text class="btn" @click="to_comment()">评价</text>
				</template>
			</view>
		</view>
		
		<view class="detail">
			<view class="item">
				<text class="label">实付款：</text>
				<text class="value" style="color: #000; font-size: 32rpx;">￥{{ getAmount() }}</text>
			</view>
			<view class="item">
				<text class="label">订单编号：</text>
				<text class="value">{{ detail.orderId }}</text>
			</view>
			<view class="item">
				<text class="label">创建日期：</text>
				<text class="value">{{ detail.createTime }}</text>
			</view>
		</view>
		
	</view>
</template>

<script>
	import topBar from "@/components/top-bar/top-bar.vue";
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import vcEmpty from "@/components/vc-empty/vc-empty.vue";
	//import vcOrderSkill from "@/components/vc-order-skill/vc-order-skill.vue"
	import param from "../../constant/param"
	import {
		getOrderState,
		updateStoreCart,
		deleteStoreCart,
		getStoreCart,
		goodsUnifieldOrder,
		toPay,
		queryStoreOrderCart,
		expeditingDelivery,
		receiveStoreOrderCart
	} from '../../api/order/orderApi.js';
	import conf from '@/conf/config.js';

	export default {
		components: {
			topBar
		},
		data() {
			return {
				conf: {},
				logi_corp: "",
				logi_no: "",
				logistics: [],
				shopType: param.CART_TYPE.SHOP,
				homeMakingType: param.CART_TYPE.HOMEMAKING,
				tabCurrentIndex: 1001,
				userInfo: {},
				cond: {
					userId: this.vc.getCurrentUser().userId,
					pagesize: 10,
					pagefrom: 1,
					stat: ""
				},
				cartFlag: false,
				stat: 0,
				noPic: conf.commonBaseUrl+'h5/static/noPic.png',
				detail: {}
			};
		},
		onLoad(options) {
			this.detail = options;
			console.log(options,99)
		},
		
		onShow() {
		},
		
		onReachBottom() {
		},
		
		methods: {
			getAmount() {
				let detail = this.detail;
				let _totalPrice = parseFloat(detail.cartNum) * parseFloat(detail.price);
				return _totalPrice.toFixed(2);
			},
			cancelOrder(e) {
				let _that = this;
				uni.showModal({
					title: '温馨提示',
					content: '确定取消订单？',
					success: function(res) {
						if (res.confirm) {
							deleteStoreCart({
									cartId: e.cartId,
									shopId: e.shopId
								})
								.then(res => {
									if (res.code == 0) {
										_that.vc.toast({
											icon: 'none',
											title: '删除成功'
										});
										_that.reload_list();
										return;
									}
								})
						}
					}
				});
			},
			toServicesPay() {
				let item = this.detail;
				this.vc.navigateTo({
					url: '/pages/homemaking/createOrder?cartId=' + item.cartId + '&shopId=' + item.shopId
				})
			},
			to_return() {
				let e = this.detail;
				this.vc.navigateTo({
					url: '/pages/storeOrderCartReturn/storeOrderCartReturn?shopId=' + e.shopId +
						"&orderId=" + e.orderId + "&cartId=" + e.cartId
				})
			},
			_expeditingDelivery: function() {
				let _cart = this.detail;
				let _that = this;
				let _eventMsg = "";
				let _title = "";
				if (this.shopType == _cart.cartType) {
					_eventMsg = "用户催发货";
					_title = "已催商家发货";
				} else {
					_eventMsg = "用户催上门";
					_title = "已催商家上门";
				}
				expeditingDelivery({
					orderId: _cart.orderId,
					cartId: _cart.cartId,
					personId: _that.vc.getCurrentUser().userId,
					eventMsg: _eventMsg,
					shopId: _cart.shopId
				}).then(_data => {
					_that.vc.toast({
						icon: 'none',
						title: _title
					})
				})
			},
			_toPay() {
				let item = this.detail;
				let _that = this;
				this.vc.navigateTo({
					url: '/pages/homemaking/homemakingPay?cartId=' + item.cartId + '&shopId=' + item.shopId
				})
			},
			to_comment() {
				let e = this.detail;
				let objType = "";
				if (this.shopType == e.cartType) {
					objType = "1001";
				} else {
					objType = "2002";
				}
				this.vc.navigateTo({
					url: '/pages/appraise/appraise?cartId=' + e.cartId + "&shopId=" + e.shopId + "&productId=" + e
						.productId + "&objType=" + objType
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.address {
		display: flex;
		padding: 30rpx;
		background: #FFF;
		.icon {
			font-size: 32rpx;
			margin-right: 10rpx;
		}
		.tel {
			color: #909399;
			font-size: 24rpx;
			margin-top: 10rpx;
		}
	}
	.goods {
		padding: 30rpx;
		margin-top: 20rpx;
		background: #FFF;
		.content {
			display: flex;
			.image, image {
				width: 120rpx;
				height: 120rpx;
				border-radius: 25rpx;
			}
			.image {
				margin-right: 25rpx;
			}
			.main {
				flex: 1;
				.head {
					display: flex;
					justify-content: space-between;
				}
				.info {
					display: flex;
					justify-content: space-between;
					color: #909399;
					font-size: 24rpx;
					margin-top: 15rpx;
				}
			}
		}
		.operate {
			display: flex;
			justify-content: flex-end;
			.btn {
				display: flex;
				justify-content: center;
				align-items: center;
				min-width: 100rpx;
				height: 52rpx;
				font-size: 24rpx;
				padding: 0 35rpx;
				margin-top: 15rpx;
				margin-left: 12rpx;
				border-radius: 10rpx;
				background: #F5F5F5;
			}
		}
	}
	.detail {
		padding: 35rpx;
		background: #FFF;
		.item {
			display: flex;
			justify-content: space-between;
			color: #909399;
			margin: 35rpx 0;
		}
	}
</style>